home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 1 of 3 / CHAPTE20 / EX7.C < prev    next >
C/C++ Source or Header  |  1995-03-22  |  3KB  |  64 lines

  1. #include <genstub.c>
  2.  
  3. // WndProc Window message procedure
  4. LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  5. {
  6.    static TCHAR szOldConfiguration[33];
  7.    switch (uMsg)   // Process Windows messages. 
  8.    {
  9.       case WM_CREATE:
  10.             GetProfileString( "Ports",             // Section Name
  11.                               "COM1:",             // Key Name
  12.                               "9600,n,8,1,x" ,     // Default COM1 settings
  13.                               szOldConfiguration,  // Old configuration buffer.
  14.                               32 );                // Buffer Size
  15.             return DefWindowProc( hWnd, uMsg, wParam, lParam );
  16.  
  17.       case WM_COMMAND:   // Process the menu items.
  18.             switch ( LOWORD( wParam ) )
  19.                 {
  20.                    case IDM_TEST:            // Write the tick count to the INI file 
  21.                        WriteProfileString( "Ports",           // Section Name.
  22.                                            "COM1:",           // Key Name.
  23.                                            "14400,n,8,1,x" ); // New configuration.
  24.                        InvalidateRect( hWnd, NULL, TRUE );
  25.                        UpdateWindow( hWnd );
  26.                        break;
  27.                    case IDM_EXIT:
  28.                        DestroyWindow( hWnd );
  29.                        break;
  30.                 }
  31.             break;
  32.       case WM_PAINT: 
  33.          {
  34.             PAINTSTRUCT ps;
  35.             TCHAR szBuffer[128];
  36.             TCHAR szCurrentConfiguration[33];
  37.             BeginPaint( hWnd, &ps );
  38.             wsprintf( szBuffer, "Old Configuration:     %s", szOldConfiguration );
  39.             TextOut( ps.hdc, 0, 0, szBuffer, lstrlen( szBuffer ) );
  40.             GetProfileString( "Ports",             // Section Name
  41.                               "COM1:",             // Key Name
  42.                               "9600,n,8,1,x" ,     // Default COM1 settings
  43.                               szCurrentConfiguration, // Input buffer.
  44.                               32 );                // Buffer Size
  45.             wsprintf( szBuffer, "Current Configuration: %s", 
  46.                       szCurrentConfiguration );
  47.             TextOut( ps.hdc, 0, 20, szBuffer, lstrlen( szBuffer ) );
  48.             EndPaint( hWnd, &ps );
  49.          }
  50.          break;
  51.       case WM_DESTROY: 
  52.             WriteProfileString( "PORTS",               // Section Name.
  53.                                 "COM1:",               // Key Name.
  54.                                 szOldConfiguration );  // Value to restore.
  55.             PostQuitMessage( 0 );
  56.       break;
  57.       default:
  58.             return DefWindowProc( hWnd, uMsg, wParam, lParam );
  59.    }
  60.    return( 0L );
  61. }
  62.  
  63. #include <about.c>
  64.